package lock;

import java.util.HashMap;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author bc
 * @Description: 普通锁
 * @date 2024/03/11
 */
@SuppressWarnings("all")
public class LockDemo {

    static ReentrantLock lock = new ReentrantLock();
    static MyReentrantLock lock1 = new MyReentrantLock();

    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
//            lock.lock();
            lock1.lock();
            lock1.lock();
            try {
                System.out.println("t1 Start!");

                Thread.sleep(3000);

                System.out.println("t1 End!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock1.unlock();
                lock1.unlock();
            }
        });

        Thread t2 = new Thread(() -> {
            System.out.println("t2 Start!");

            while(lock1.isLock()) {
        
            }

            System.out.println("t2 End!");
        });

        t2.start();
        t1.start();
    }
}
